#include "ZImageManager.h"

GLOBAL_NAMESPACE_BEGIN

//template<> ImageManager* Singleton<ImageManager>::singleton_ = 0; 

ImageManager::ImageManager()
{
}

ImageManager::~ImageManager()
{
    destroy();
}

void ImageManager::destroy()
{
    for (ImageList::iterator it = images_.begin(); it!=images_.end(); ++it)
    {
        if (*it) delete (*it);
    }
    images_.clear();
}

void ImageManager::clear()
{
    destroy();
}

void ImageManager::init()
{
}

void ImageManager::addImage(ImageSpace::Image* ima)
{
    images_.push_back(ima);
}

void ImageManager::removeImage(ImageSpace::Image* ima)
{
    ImageList::iterator findIt = std::find(images_.begin(), images_.end(), ima);
    if (findIt!=images_.end())
        images_.erase(findIt);
    else
        return;
}

int ImageManager::getImageCount()
{
    return images_.size();
}

ImageSpace::Image* ImageManager::getImageAt(int idx)
{
    if (idx<0 || idx>getImageCount())
        return NULL;

    return images_[idx];
}

GLOBAL_NAMESPACE_END